package com.yxkj.syh.app.huarong.data_center.model;

import com.syh.app.basic.utils.net.ApiObserver;
import com.yxkj.syh.app.huarong.util.RetrofitHelper;
import com.trello.rxlifecycle2.LifecycleTransformer;
import com.yxkj.syh.app.huarong.api.AccountApi;

import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * 创建者：SYH
 * 时间：2020/5/22 13:57
 * 编辑者：SYH、
 * 标签：
 * 补充说明：
 */
public class AccountModel {
    private static AccountModel accountModel;

    private AccountModel() {
    }

    public static AccountModel getAccountModel() {
        if (accountModel == null) accountModel = new AccountModel();
        return accountModel;
    }

    private AccountApi getAccountApi() {
        return RetrofitHelper.createApi(AccountApi.class);
    }

    public void setLoginPwd(Map<String, Object> pMap, LifecycleTransformer transformer, ApiObserver apiObserver) {
        getAccountApi().setPwd(pMap).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }
    public void verCode( LifecycleTransformer transformer, ApiObserver apiObserver) {
        getAccountApi().verCode().compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void userInfo(LifecycleTransformer transformer, ApiObserver apiObserver) {
        getAccountApi().userInfo().compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }
    public void userMainInfo(LifecycleTransformer transformer, ApiObserver apiObserver) {
        getAccountApi().userMainInfo().compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }
    public void saveOrEditAddress(Map<String,Object> info,LifecycleTransformer transformer, ApiObserver apiObserver) {
        getAccountApi().saveOrEditAddress(info).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

}
